package com.example.demo.Controller;

import com.example.demo.Bean.*;
import com.example.demo.Service.ProductShowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ProductsController {
    @Autowired
    private ProductShowService productShowService;

    @GetMapping("/getShowProduct")
    public List<ProductsShow> getShowProduct(String brand,String category,Integer page){
        SelectParameter selectParameter = new SelectParameter();
        if (page == 1){
            Integer limit = 0;
            selectParameter.setBrand(brand);
            selectParameter.setCategory(category);
            selectParameter.setPage(limit);
            return productShowService.getShowProduct(selectParameter);
        }else {
            Integer limit = (page-1)*10;
            selectParameter.setBrand(brand);
            selectParameter.setCategory(category);
            selectParameter.setPage(limit);
            return productShowService.getShowProduct(selectParameter);
        }
    }
    
    @GetMapping("/getCountProduct")
    public Integer getCountProduct(String brand,String category){
        SelectParameter selectParameter = new SelectParameter();
        selectParameter.setBrand(brand);
        selectParameter.setCategory(category);
        return productShowService.getCountProduct(selectParameter);
    }

    @GetMapping("/getShowCategory")
    public List<ProductsShow> getShowCategory(String category,Integer page){
        SelectParameter selectParameter = new SelectParameter();
        if (page == 1){
            Integer limit = 0;
            selectParameter.setCategory(category);
            selectParameter.setPage(limit);
            return productShowService.getShowCategory(selectParameter);
        }else {
            Integer limit = (page-1)*10;
            selectParameter.setCategory(category);
            selectParameter.setPage(limit);
            return productShowService.getShowCategory(selectParameter);
        }
    }

    @GetMapping("/getCountCategory")
    public int getCountCategory(String category){
        SelectParameter selectParameter = new SelectParameter();
        selectParameter.setCategory(category);
        return productShowService.getCountCategory(selectParameter);
    }

    @GetMapping("/getShowByLike")
    public List<ProductsShow> getShowByLike(String title,Integer page){
        LikeParameter likeParameter = new LikeParameter();
        if (page == 1){
            Integer limit = 0;
            likeParameter.setTitle(title);
            likeParameter.setPage(limit);
            return productShowService.getShowByLike(likeParameter);
        }else {
            Integer limit = (page-1)*10;
            likeParameter.setTitle(title);
            likeParameter.setPage(limit);
            return productShowService.getShowByLike(likeParameter);
        }
    }

    @GetMapping("getCountLike")
    public Integer getCountLike(String title){
        return productShowService.getAllShowLike(title).size();
    }

    @GetMapping("/getDetail")
    public Detail getDetail(DetailParameter detailParameter){
        return productShowService.getDetailProduct(detailParameter);
    }

    @GetMapping("/getComment")
    public List<Comment> getComment(CommentParameter commentParameter){
        return productShowService.getComment(commentParameter);
    }

}
